package com.hakgc.rent.service.impl;

import com.hakgc.rent.dao.DistrictDao;
import com.hakgc.rent.dao.StreetDao;
import com.hakgc.rent.dao.impl.DistrictDaoImpl;
import com.hakgc.rent.dao.impl.StreetDaoImpl;
import com.hakgc.rent.entity.Street;
import com.hakgc.rent.service.StreetService;

import java.util.List;

/**
 * @author Xing.Jiejian
 * @date 2020/11/14
 */
public class StreetServiceImpl implements StreetService {
    private StreetDao streetDao = new StreetDaoImpl();
    private DistrictDao districtDao = new DistrictDaoImpl();

    @Override
    public List<Street> findByPage(String name, int did, int pageNo, int pageSize, boolean withDistrict) {
        int offset = (pageNo-1)*pageSize;
        List<Street> streets = streetDao.findByLimit(name,did,offset,pageSize);
        // 如果需要查询关联区县对象
        if (withDistrict && streets!= null){
            for (Street street : streets) {
                street.setDistrict(districtDao.findById(street.getDistrictId()));
            }
        }
        return streets;
    }

    @Override
    public int getCount(String name, int did) {
        return streetDao.getCount(name, did);
    }

    @Override
    public boolean deleteById(int id) {
        return streetDao.deleteById(id);
    }

    @Override
    public Street findById(int id) {
        return streetDao.findById(id);
    }
}
